import {
  API_getClassList,
  API_getClassMine,
  API_getCollegeList,
  API_getDepartmentList,
  API_getDepartmentStaffs,
  API_getGradeList,
  API_getGroupList,
  API_getGroupMine,
  API_getIdentityList,
  API_getMajorList,
  API_getMyCollegeClass,
  API_getMyCollegeStudent,
  API_getMyCollegeTeacher,
  API_getUserIdentity,
  API_getUserParents,
  API_getUserStudents,
  API_getUserTeachers,
} from "../../../../network/servers";
import getInfo from "../../utils/getInfo";
import { formatData } from "./schoolType2";

/**大学 */
export const getNewData1 = {
  getIdentity(data, receivers, fnSet) {
    console.log("获取选择列表参数=====", data, receivers, fnSet);
    return new Promise<any>((resolve, reject) => {
      let identities = receivers.identities;
      let persons = receivers.persons;
      if (data.type.length == 1) {
        let params = {
          schoolId: getInfo.getSchoolId(),
          userType: "0,11",
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getIdentityList(params, header).then((res) => {
          console.log(
            "API-获取管理员身份列表（大学）:",
            res,
            "\nparams:",
            params
          );
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = identities?.findIndex(
                (pItem) => pItem.identityCode == item.identityCode
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                identities.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.identityName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 2) {
        let params = {
          schoolId: getInfo.getSchoolId(),
          identityCode: data.Info.identityCode,
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getUserIdentity(params, header).then((res) => {
          console.log("API-获取管理员用户（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = persons?.findIndex(
                (pItem) => pItem.userId == item.userId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                persons.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.userName,
                subData: [],
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      }
    });
  },

  getTeachers(data, receivers, fnSet) {
    return new Promise<any>((resolve, reject) => {
      let teachers = receivers?.teachers;
      let persons = receivers?.persons;
      if (data.type.length == 1) {
        let params = {
          identityType: 1,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getCollegeList(params, header).then((res) => {
          console.log("API-获取学院列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = teachers?.findIndex(
                (pItem) => pItem.collegeId == item.collegeId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                teachers.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.collegeName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 2) {
        let params = {
          schoolType: 1,
          schoolId: getInfo.getSchoolId(),
          collegeId: data.Info.collegeId,
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getGroupList(params, header).then((res) => {
          console.log("API-获取教研组列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = teachers?.findIndex(
                (pItem) => pItem.groupId == item.groupId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                teachers.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.groupName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 3) {
        let params = {
          schoolType: 1,
          groupId: data.Info.groupId,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getUserTeachers(params, header).then((res) => {
          console.log("API-获取教师用户（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = persons?.findIndex(
                (pItem) => pItem.userId == item.userId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                persons.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.userName,
                subData: [],
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      }
    });
  },

  getStudents(data, receivers, fnSet) {
    return new Promise<any>((resolve, reject) => {
      let students = receivers.students;
      let persons = receivers.persons;
      if (data.type.length == 1) {
        let params = {
          identityType: 2,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getCollegeList(params, header).then((res) => {
          console.log("API-获取学院列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = students?.findIndex(
                (pItem) => pItem.collegeId == item.collegeId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                students.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.collegeName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 2) {
        let params = {
          collegeId: data.Info.collegeId,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getMajorList(params, header).then((res) => {
          console.log("API-获取专业列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = students?.findIndex(
                (pItem) => pItem.majorId == item.majorId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                students.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.majorName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 3) {
        let majorId = data.Info.majorId;
        let params = {
          schoolType: 1,
          schoolId: getInfo.getSchoolId(),
          majorId: majorId,
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getGradeList(params, header).then((res) => {
          console.log("API-获取年级列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = students?.findIndex(
                (pItem) => pItem.gradeId == item.gradeId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                students.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.gradeName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
                majorId,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 4) {
        let params = {
          schoolType: 1,
          sysId: getInfo.getSysId(),
          gradeId: data.Info.gradeId,
          majorId: data.majorId,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getClassList(params, header).then((res) => {
          console.log("API-获取班级列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = students?.findIndex(
                (pItem) => pItem.classId == item.classId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                students.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.className,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 5) {
        let params = {
          schoolType: 1,
          classId: data.Info.classId,
          schoolId: getInfo.getSchoolId(),
          // classType:data.Info.classType
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getUserStudents(params, header).then((res) => {
          console.log("API-获取学生用户（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = persons?.findIndex(
                (pItem) => pItem.userId == item.userId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                persons.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.userName,
                subData: [],
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      }
    });
  },

  getParents(data, receivers, fnSet) {
    return new Promise<any>((resolve, reject) => {
      let parents = receivers.parents;
      let persons = receivers.persons;
      if (data.type.length == 1) {
        let params = {
          identityType: 2,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getCollegeList(params, header).then((res) => {
          console.log("API-获取学院列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = parents?.findIndex(
                (pItem) => pItem.collegeId == item.collegeId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                parents.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.collegeName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 2) {
        let params = {
          collegeId: data.Info.collegeId,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getMajorList(params, header).then((res) => {
          console.log("API-获取专业列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = parents?.findIndex(
                (pItem) => pItem.majorId == item.majorId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                parents.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.majorName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 3) {
        let majorId = data.Info.majorId;
        let params = {
          schoolType: 1,
          schoolId: getInfo.getSchoolId(),
          majorId: majorId,
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getGradeList(params, header).then((res) => {
          console.log("API-获取年级列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = parents?.findIndex(
                (pItem) => pItem.gradeId == item.gradeId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                parents.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.gradeName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
                majorId,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 4) {
        let params = {
          schoolType: 1,
          sysId: getInfo.getSysId(),
          gradeId: data.Info.gradeId,
          majorId: data.majorId,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getClassList(params, header).then((res) => {
          console.log("API-获取班级列表（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = parents?.findIndex(
                (pItem) => pItem.classId == item.classId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                parents.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.className,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 5) {
        let params = {
          schoolType: 1,
          classId: data.Info.classId,
          // classType:data.Info.classType,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getUserParents(params, header).then((res) => {
          console.log("API-获取家长用户（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = persons?.findIndex(
                (pItem) => pItem.userId == item.userId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                persons.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.userName,
                subData: [],
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      }
    });
  },

  getDepartment(data, receivers, fnSet) {
    return new Promise<any>((resolve, reject) => {
      let departments = receivers.departments;
      let persons = receivers.persons;
      if (data.type.length == 1) {
        let params1 = {
          sysId: getInfo.getSysId(),
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getDepartmentList(params1, header).then((res1) => {
          console.log(
            "API-获取学校组织结构（大学）:",
            res1,
            "\nparams:",
            params1
          );
          if (res1.code == 200) {
            let fnArr: any = [];
            const result = res1.data;
            formatData(result, departments, persons, data.type);
            result.map((item, index) => {
              let hasCho = 0;
              let idIndex = departments?.findIndex(
                (pItem) => pItem.departmentId == item.departmentId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                departments.splice(idIndex, 1);
                hasCho = 1;
              }
              fnArr.push({
                name: item.name,
                subData: item.subData,
                hasCho: item.hasCho || hasCho,
                index,
                type: item.type,
                Info: item.Info,
                nodeType: item.nodeType || "",
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else {
        let params1 = {
          sysId: getInfo.getSysId(),
          schoolId: getInfo.getSchoolId(),
          departmentId: data.Info.departmentId,
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getDepartmentList(params1, header).then((res1) => {
          console.log("API-获取部门列表（大学）:", res1, "\nparams:", params1);
          if (res1.code == 200) {
            let fnArr: any = [];
            res1.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = departments?.findIndex(
                (pItem) => pItem.departmentId == item.departmentId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                departments.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.departmentName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            let header = {
              Authorization: getInfo.getToken(),
            };
            API_getDepartmentStaffs(params1, header).then((res2) => {
              console.log(
                "API-获取部门员工（大学）:",
                res2,
                "\nparams:",
                params1
              );
              if (res2.code == 200) {
                res2.data.map((item, index) => {
                  let hasCho = 0;
                  let idIndex = persons?.findIndex(
                    (pItem) => pItem.userId == item.userId
                  );
                  if (idIndex == undefined || idIndex == -1) {
                    if (data.hasCho == 1) {
                      //父项，是否选中
                      hasCho = 1;
                    } else {
                      hasCho = 0;
                    }
                  } else {
                    persons.splice(idIndex, 1);
                    hasCho = 1;
                  }
                  let typeArr = JSON.parse(JSON.stringify(data.type));
                  typeArr.push(index);
                  fnArr.push({
                    name: item.userName,
                    subData: [],
                    hasCho: hasCho,
                    index,
                    type: typeArr,
                    Info: item,
                  });
                });
                fnSet(receivers);
                resolve(fnArr);
              } else {
                fnSet(receivers);
                resolve(fnArr);
              }
            });
          } else {
            resolve([]);
          }
        });
      }
    });
  },

  getMyClass(data, receivers, fnSet) {
    return new Promise<any>((resolve, reject) => {
      let students = receivers.students;
      let persons = receivers.persons;
      if (data.type.length == 1) {
        //我的班级第1层（大学）
        let params = {
          schoolType: getInfo.getSchoolType(),
          userId: getInfo.getUserId(),
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getClassMine(params, header).then((res) => {
          console.log("API-获取我的班级列表:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = students?.findIndex(
                (pItem) => pItem.classId == item.classId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                students.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.className,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 2) {
        //我的班级第2层（大学）
        let params = {
          schoolType: getInfo.getSchoolType(),
          classId: data.Info.classId,
          classType: data.Info.classType,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getUserStudents(params, header).then((res) => {
          console.log("API-获取学生用户（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = persons?.findIndex(
                (pItem) => pItem.userId == item.userId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                persons.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.userName,
                subData: [],
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      }
    });
  },

  getMyClassParents(data, receivers, fnSet) {
    return new Promise<any>((resolve, reject) => {
      let parents = receivers.parents;
      let persons = receivers.persons;
      if (data.type.length == 1) {
        //学生家长第1层（大学）
        let params = {
          schoolType: getInfo.getSchoolType(),
          userId: getInfo.getUserId(),
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getClassMine(params, header).then((res) => {
          console.log(
            "API-获取我的班级列表（学生家长）:",
            res,
            "\nparams:",
            params
          );
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = parents?.findIndex(
                (pItem) => pItem.classId == item.classId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                parents.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.className,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 2) {
        //学生家长第2层（大学）
        let params = {
          schoolType: 1,
          classId: data.Info.classId,
          classType: data.Info.classType,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getUserParents(params, header).then((res) => {
          console.log("API-获取家长用户（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = persons?.findIndex(
                (pItem) => pItem.userId == item.userId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                persons.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.userName,
                subData: [],
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      }
    });
  },

  getTeacherGroup(data, receivers, fnSet) {
    return new Promise<any>((resolve, reject) => {
      let teachers = receivers.teachers;
      let persons = receivers.persons;
      if (data.type.length == 1) {
        //我的教师组第1层（大学）
        let params = {
          schoolType: getInfo.getSchoolType(),
          userId: getInfo.getUserId(),
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getGroupMine(params, header).then((res) => {
          console.log("API-获取我的教研组（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = teachers?.findIndex(
                (pItem) => pItem.groupId == item.groupId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                teachers.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.groupName,
                subData: undefined,
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      } else if (data.type.length == 2) {
        //我的教师组第2层（大学）
        let params = {
          schoolType: 1,
          groupId: data.Info.groupId,
          schoolId: getInfo.getSchoolId(),
        };
        let header = {
          Authorization: getInfo.getToken(),
        };
        API_getUserTeachers(params, header).then((res) => {
          console.log("API-获取教师用户（大学）:", res, "\nparams:", params);
          if (res.code == 200 && res.data.length != 0) {
            let fnArr: any = [];
            res.data.map((item, index) => {
              let hasCho = 0;
              let idIndex = persons?.findIndex(
                (pItem) => pItem.userId == item.userId
              );
              if (idIndex == undefined || idIndex == -1) {
                if (data.hasCho == 1) {
                  //父项，是否选中
                  hasCho = 1;
                } else {
                  hasCho = 0;
                }
              } else {
                persons.splice(idIndex, 1);
                hasCho = 1;
              }
              let typeArr = JSON.parse(JSON.stringify(data.type));
              typeArr.push(index);
              fnArr.push({
                name: item.userName,
                subData: [],
                hasCho: hasCho,
                index,
                type: typeArr,
                Info: item,
              });
            });
            fnSet(receivers);
            resolve(fnArr);
          } else {
            resolve([]);
          }
        });
      }
    });
  },

  /** 获取我的院系教师 */
  getMyCollegeTeacher(data, receivers, fnSet) {
    return new Promise<any>((resolve, reject) => {
      let persons = receivers?.persons;
      let params = {
        schoolType: getInfo.getSchoolType(),
        collegeId: getInfo.getCollegeId(),
        schoolId: getInfo.getSchoolId(),
      };
      let header = {
        Authorization: getInfo.getToken(),
      };
      API_getMyCollegeTeacher(params, header).then((res) => {
        console.log("API-获取我的院系教师（大学）:", res, "\nparams:", params);
        if (res.code == 200 && res.data.length != 0) {
          let fnArr: any = [];
          const result = res.data;
          formatData(result, [], persons, data.type);
          result.map((item, index) => {
            let hasCho = 0;
            let idIndex = persons?.findIndex(
              (pItem) => pItem.userId == item.userId
            );
            if (idIndex == undefined || idIndex == -1) {
              if (data.hasCho == 1) {
                //父项，是否选中
                hasCho = 1;
              } else {
                hasCho = 0;
              }
            } else {
              persons.splice(idIndex, 1);
              hasCho = 1;
            }
            let typeArr = JSON.parse(JSON.stringify(data.type));
            typeArr.push(index);
            fnArr.push({
              name: item.userName,
              subData: [],
              hasCho: hasCho,
              index,
              type: typeArr,
              Info: item,
            });
          });
          fnSet(receivers);
          resolve(fnArr);
        } else {
          resolve([]);
        }
      });
    });
  },
  /** 获取本系学生 */
  getMyCollegeStudent(data, receivers, fnSet) {
    return new Promise<any>((resolve, reject) => {
        let classes = receivers.classes;
        let persons = receivers.persons;
        if (data.type.length == 1) {
          //我的班级第1层（大学）
          let params = {
            schoolType: getInfo.getSchoolType(),
            collegeId: getInfo.getCollegeId(),
          };
          let header = {
            Authorization: getInfo.getToken(),
          };
          API_getMyCollegeClass(params, header).then((res) => {
            console.log("API-获取我的院系班级列表（大学）:", res, "\nparams:", params);
            if (res.code == 200 && res.data.length != 0) {
              let fnArr: any = [];
              const result=res.data
              formatData(result,[],persons,data.type)
              result.map((item, index) => {
                let hasCho = 0;
                let idIndex = classes?.findIndex(
                  (pItem) => pItem.classId == item.classId
                );
                if (idIndex == undefined || idIndex == -1) {
                  if (data.hasCho == 1) {
                    //父项，是否选中
                    hasCho = 1;
                  } else {
                    hasCho = 0;
                  }
                } else {
                  classes.splice(idIndex, 1);
                  hasCho = 1;
                }
                let typeArr = JSON.parse(JSON.stringify(data.type));
                typeArr.push(index);
                fnArr.push({
                  name: item.className,
                  subData: undefined,
                  hasCho: hasCho,
                  index,
                  type: typeArr,
                  Info: item,
                });
              });
              fnSet(receivers);
              resolve(fnArr);
            } else {
              resolve([]);
            }
          });
        } else if (data.type.length == 2) {
          //我的班级第2层（大学）
          let params = {
            schoolType: getInfo.getSchoolType(),
            classId: data.Info.classId,
            schoolId: getInfo.getSchoolId(),
          };
          let header = {
            Authorization: getInfo.getToken(),
          };
          API_getMyCollegeStudent(params, header).then((res) => {
            console.log("API-获取学生用户（大学）:", res, "\nparams:", params,"data:",persons);
            if (res.code == 200 && res.data.length != 0) {
              let fnArr: any = [];
              const result=res.data
              formatData(result,[],persons,data.type)
              result.map((item, index) => {
                let hasCho = 0;
                let idIndex = persons?.findIndex(
                  (pItem) => pItem.userId == item.userId
                );
                if (idIndex == undefined || idIndex == -1) {
                  if (data.hasCho == 1) {
                    //父项，是否选中
                    hasCho = 1;
                  } else {
                    hasCho = 0;
                  }
                } else {
                  persons.splice(idIndex, 1);
                  hasCho = 1;
                }
                let typeArr = JSON.parse(JSON.stringify(data.type));
                typeArr.push(index);
                fnArr.push({
                  name: item.userName,
                  subData: [],
                  hasCho: hasCho,
                  index,
                  type: typeArr,
                  Info: item,
                });
              });

              fnSet(receivers);
              resolve(fnArr);
            } else {
              resolve([]);
            }
          });
        }
      });
  },
};
